package com.tanhua.server.config;

import com.tanhua.server.interceptors.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 代替springmvc.xml配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 添加拦截器
     * @param registry 拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册了拦截器
        registry.addInterceptor(tokenInterceptor)
        .addPathPatterns("/**") // 要拦截的路径
                // 发送验证码与校验要放行
        .excludePathPatterns("/user/login","/user/loginVerification"); // 放行的路径
    }
}
